<template>
    <div class="materialsAudit-container">
        <BaseAudit ref="baseAudit" :callbackFn="callbackFn" :submitData="childSubmitData">
            <template slot="extraOption" v-if="taskDefKey === 'legal_general_base_change_cser_audit'">
                <title-name title="选择岗位"></title-name>
                <div class="mb20">
                    <a-row>
                        <a-col :span="12">
                            <a-form-model-item class="approval-item" label="组织" prop="orgSelectedName">
                                <TreeSelectOrganization
                                    v-model="form.orgSelectedName"
                                    :orgSelectedValue.sync="form.orgSelectedName"
                                    :orgSelectedLabel.sync="form.orgSelectedLabel"
                                    :orgQuery="{pid:orgId,cascade:true}"
                                    childrenNode="jobs"
                                ></TreeSelectOrganization>
                            </a-form-model-item>
                        </a-col>
                        <a-col :span="12">
                            <a-form-model-item class="approval-item" label="岗位" prop="jobsSelectedName">
                                <Jobs
                                    v-model="form.jobsSelectedName"
                                    :selectedValue.sync="form.jobsSelectedName"
                                    :treeCheckable="true"
                                    :addTitel="form.orgSelectedLabel[0]"
                                ></Jobs>
                            </a-form-model-item>
                        </a-col>
                    </a-row>
                </div>
            </template>
            <template slot="extraOption" v-if="taskDefKey === 'legal_general_base_change_cec_audit'">
                <title-name title="是否有重大风险"></title-name>
                <div class="mb20">
                    <a-select
                        style="width: 100%;"
                        mode="single"
                        v-model="isImportant"
                        placeholder="请选择">
                        <a-select-option value="1">是</a-select-option>
                        <a-select-option value="0">否</a-select-option>
                    </a-select>
                </div>
            </template>
        </BaseAudit>
    </div>
</template>

<script>
/*
* 总包合同审批基本信息变更审批专用
* */
import BaseAudit from '../BaseAudit'
import TotalPackageContractAdd from '@/views/Legal/branchContract/totalPackageContract/add'
import { getPostManageList2 } from '@/api/system/system'
import TreeSelectOrganization from '@/components/TreeSelectOrganization'
import Jobs from '@/components/TreeSelectOrganization/jobs'

export default {
    name: 'TotalPackageBaseChangeAudit',
    components: {
        BaseAudit,
        TreeSelectOrganization,
        Jobs
    },
    data() {
        return {
            form: {
                orgSelectedName: '',
                orgSelectedLabel: '',
                jobsSelectedName: undefined, //岗位
                respEmployeeId: undefined //人员
            },
            taskDefKey: this.$route.query.taskDefKey,
            orgId: '',
            isImportant: ''
        }
    },
    created() {
        this.getOrgId()
    },
    computed: {
        childSubmitData() {
            if (this.taskDefKey === 'legal_general_base_change_cser_audit') {
                const { jobsSelectedName } = this.form
                return {
                    assignVariableType: 3,
                    assignVariableValue: jobsSelectedName ? jobsSelectedName.join(',') : ''
                }
            } else if (this.taskDefKey === 'legal_general_base_change_cec_audit') {
                return {
                    isImportant: this.isImportant
                }
            }
        }
    },
    methods: {
        callbackFn(type) {
            if (type !== 'approval') return true
            // if (true) {
            if (this.taskDefKey === 'legal_general_base_change_cser_audit') {
                const { jobsSelectedName } = this.form
                if (jobsSelectedName === undefined || jobsSelectedName.length === 0) {
                    this.$noticeWarning('请选择岗位')
                    return false
                }
            } else if (this.taskDefKey === 'legal_general_base_change_cec_audit') {
                if (this.isImportant === '') {
                    this.$noticeWarning('请选择是否有重大风险')
                    return false
                }
            }
            return true
        },
        async getOrgId() {
            let levels = JSON.parse(sessionStorage.getItem('ycloud-user_info')).employee.levels
            if (levels && levels.length) {
                let res = levels.filter(v => v.code === 'PD')
                if (!res.length) {
                    res = levels.filter(v => v.code === 'BC')
                }
                if (!res.length) {
                    res = levels.filter(v => v.code === 'CO')
                }
                if (res.length) {
                    this.orgId = res[0].id
                }
            }
        }
    }
}
</script>

<style lang="less" scoped>
.materialsAudit-container {
    /deep/ .approval-item {
        display: flex;
    }
}
</style>